package com.clear.honghefinance.common.dto.entity;

import lombok.Getter;

import java.util.List;
import java.util.Objects;

/**
 * @author 程序员clear
 */
public abstract class TreeNode {

    /**
     * 子节点数据
     */
    @Getter
    private List<TreeNode> childrenNode;

    /**
     * 是否根节点
     */
    @Getter
    private Boolean rootNode;

    /**
     * 是否叶子节点
     **/
    @Getter
    private Boolean leafNode;

    /**
     * 获取父级节点id
     *
     * @return 父级节点id
     */
    public abstract Integer getNodePid();

    /**
     * 获取当前节点id
     *
     * @return 当前节点id
     */
    public abstract Integer getNodeId();

    /**
     * 设置子节点数据
     *
     * @param children 子节点数据
     */
    public void setChildrenNode(List<TreeNode> children) {
        this.childrenNode = children;
        this.rootNode = Objects.equals(getNodePid(), 0);    // 判断是否是根节点的重要依据
        this.leafNode = children == null || children.isEmpty();
    }
}
